<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/11/26
 * Time: 10:26
 */
namespace app\admin\controller;
use think\Db;
class Supermoney extends Base {

    public function index()
    {
        if (request()->isAjax()) {
            $params = input('param.');
            if (isset($params['tu_status']) && $params['tu_status'] != '') {
                if($params['tu_status'] == 2){
                    $where['tu_status'] = 2;
                }else{
                    $where['tu_status'] = ['<>',2];
                }
            }
            $where['a.task_status'] = array('NEQ', 5);
            $where['a.task_active'] = 3;
            $where['a.task_super'] = 2;
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('task')->alias('a')
                ->join('up_shops us', 'us.s_id = a.task_s_id', 'left')
                ->join('up_task_user tu', 'a.task_id = tu.tu_task_id', 'left')
                ->join('up_super su', 'tu.tu_user_id = su.sup_user_id', 'left')
                ->where($where)->count();// 获取总条数
            $lists = Db::name('task')->alias('a')
                ->join('up_shops us', 'us.s_id = a.task_s_id', 'left')
                ->join('up_task_user tu', 'a.task_id = tu.tu_task_id', 'left')
                ->join('up_super su', 'tu.tu_user_id = su.sup_user_id', 'left')
                ->where($where)
//                ->field('a.*,us.s_name,us.s_image,sup_name,sup_goods,is_super,tu_super_yes')
                ->order('task_update_time desc')
                ->page($Nowpage, $limits)
                ->select();
            foreach ($lists as $key => &$vo) {
                if ($vo['task_status'] == 1) {
                    $vo['task_status_name'] = '上架';
                } elseif ($vo['task_status'] == 2) {
                    $vo['task_status_name'] = '上架';
                } elseif ($vo['task_status'] == 3) {
                    $vo['task_status_name'] = '上架';
                } elseif ($vo['task_status'] == 4) {
                    $vo['task_status_name'] = '下架';
                }

                $vo['wcl'] = ($vo['task_done_num'] / $vo['task_num']) * 100 . '%';
//               $district = Db::table('up_area')->where('district_id',$vo['task_shi'])->value('district');
//               $district1 = Db::table('up_area')->where('district_id',$vo['task_qu'])->value('district');
                if ($vo['task_sheng'] == 0) {
                    $vo['address'] = '全国';
                } else {
                    $city = Db::name('area')
                        ->whereIn('district_id', $vo['task_sheng'])
                        ->column('district');
                    $vo['address'] = implode(',', $city);
                }
//               $vo['address'] = $district.$district1;
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $allmoney = Db::name('task')->alias('a')
            ->join('up_task_user tu', 'a.task_id = tu.tu_task_id', 'left')
            ->where('task_active',3)
            ->where('task_super',2)
            ->field('sum(task_super_admin_money) as allmoney')
            ->find();// 获取总条数
        $this->assign('allmoney',$allmoney);
        return $this->fetch();
    }


}